package com.itstyle.quartz.job;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.StopWatch;
import org.springframework.util.concurrent.ListenableFuture;

import java.io.Serializable;
import java.util.UUID;

public class KafkaPointJob implements Job,Serializable {

    private static final long serialVersionUID = -958333297094401289L;

    private static final Logger log = LoggerFactory.getLogger(KafkaPointJob.class);

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        String message = UUID.randomUUID().toString();;
        ListenableFuture future = kafkaTemplate.send("app_log", "发送消息----zhisheng-----"+System.currentTimeMillis()+" "+message);

//        future.addCallback(o -> System.out.println("send-消息发送成功：" + message), throwable -> System.out.println("消息发送失败：" + message));


        stopWatch.stop();

        log.info("KafkaTemplate发送消息耗时: " + stopWatch.getTotalTimeMillis()+"毫秒");

    }

}
